<?php
/**
 * Created by PhpStorm.
 * User: Dick
 * Date: 2016/4/9
 * Time: 15:03
 */

namespace Controller;

use Method\JSON;
use Method\Template;
use Model\User;
use Model\UserInfo;


class PersonalPage
{
    public function jump($username)
    {
        $your = $_SESSION['user']->username;
        if ($username == $your) {
            $_SESSION['user']->towho = $username;
        } else {
            $_SESSION['user']->towho = $username;
        }
        include Template::load('Other/personal');
    }

    public function getuserinfo()
    {
        $username = $_SESSION['user']->towho;
        $result = UserInfo::GetUserInfo($username);
        JSON::json($result);
    }

    public function getfollow()
    {
//        $tableColumn = 'following';
        $tableColumn = $_POST['type'];
        $username = $_SESSION['user']->towho;
//        $username = 'dick';
        $id = User::GetIdByUsername($username);
        if ($tableColumn == 'following') {
            $tableColumn = 'followed';
            $extra = 'following = ' . $id . ' && followed != ' . $id;
        } else if ($tableColumn == 'followed') {
            $tableColumn = 'following';
            $extra = 'followed = ' . $id . ' && following != ' . $id;
        }
        UserInfo::GetUsersInfo($tableColumn, $extra);
    }
}